package com.xingkong.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xingkong.common.core.domain.Ztree;
import org.springframework.stereotype.Service;
import com.xingkong.product.mapper.CategoryMapper;
import com.xingkong.product.domain.Category;
import com.xingkong.product.service.ICategoryService;

import java.util.ArrayList;
import java.util.List;

/**
 * 商品分类 服务层实现
 *
 * @author yiyue
 * @date 2020-03-15
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements ICategoryService {


    /**
     * 查询商品分类树列表
     *
     * @return 所有商品分类信息
     */
    @Override
    public List<Ztree> selectCategoryTree(Long id) {
        Category queryCategory = new Category();

        queryCategory.setParentId(id);
        List<Category> categoryList = this.list(new QueryWrapper<Category>(queryCategory));
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (Category category : categoryList) {
            Ztree ztree = new Ztree();
            ztree.setId(category.getId());
            ztree.setpId(category.getParentId());
            ztree.setName(category.getCategoryName());
            ztree.setTitle(category.getCategoryName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}